package com.heima.controller;

import com.heima.common.Result;
import com.heima.domain.dto.RegionDto;
import com.heima.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/region")
@Api(tags = "区域管理")
public class RegionController {

    @Autowired
    private RegionService regionService;

    @GetMapping("/search")
    @ApiOperation("分页查询区域")
    public Result getByPage(@RequestParam(required = false) Integer pageIndex,
                            @RequestParam(required = false) Integer pageSize,
                            @RequestParam(required = false) String name){
        Result result = regionService.getByPage(pageIndex,pageSize,name);
        return result;
    }

    @PostMapping
    @ApiOperation("新增区域")
    public Boolean addRegion(@RequestBody RegionDto dto){
        Boolean flag = regionService.addRegion(dto);
        return flag;
    }

    @PutMapping("/{regionId}")
    @ApiOperation("修改区域")
    public Boolean updateRegion(@PathVariable String regionId,@RequestBody RegionDto dto){
        Boolean flag = regionService.updateRegion(Long.parseLong(regionId),dto);
        return flag;
    }

    @DeleteMapping("/{regionId}")
    @ApiOperation("删除区域")
    public Boolean daleteRegion(@PathVariable String regionId){
        Boolean flag = regionService.deleteRegion(Long.parseLong(regionId));
        return flag;
    }
}
